%% This m-file is to display the 2D->1D data
close all
clear all
clc

MCAfile={ % 2D data (energy,qz, intensity)
    'DPPC_Fe02uM_01.dat.scan23.mca';  % 1 
    'DPPC_Fe05uM_01.dat.scan22.mca';  % 2
    'DPPC_Fe10uM_01.dat.scan22.mca';  % 3
    'DPPC_Fe20uM_02.dat.scan22.mca';  % 4
    'DPPC_Fe40uM_01.dat.scan22.mca';  % 5
    'Subphase_Fe5mM.dat.scan12.mca';  % 6
    'Subphase_KCl100mM.dat.scan12.mca'; % 7
    }

MONfile={
    'DPPC_Fe02uM_01_scan23_mon.txt'; 
    'DPPC_Fe05uM_01_scan22_mon.txt'; 
    'DPPC_Fe10uM_01_scan22_mon.txt';
    'DPPC_Fe20uM_02_scan22_mon.txt'; 
    'DPPC_Fe40uM_01_scan22_mon.txt';
    'Subphase_Fe5mM_scan12_mon.txt';
    'Subphase_KCl100mM_scan12_mon.txt';
    }

CalibCoef=[0.0097, -0.0210];  % Channel->Energy calibration coefficients APS detector

[data,E,Q,ct]=mcaread(MCAfile{6},CalibCoef);
imagesc(Q,E(100:1000),data(100:1000,:));
set(gca, 'ydir','norm');

%% for calibration purpose
calib_temp=[1 1];
[Intensity_2D,ch,Q,ct]=mcaread(MCAfile{6},calib_temp);
%%
close all
figure
subplot(1,2,1)
hold on
Intensity_1D=sum(data,2)/20000;
plot(E,Intensity_1D,'k-','LineWidth',3);
plot([6.4 6.4],[0 1],'r-','LineWidth',3);
plot([7.05 7.05],[0 1],'r-','LineWidth',3);
plot([3.3 3.3],[0 1],'r-','LineWidth',3);
plot([3.6 3.6],[0 1],'r-','LineWidth',3);
% Txt_Save('EDDCalib.txt',ch(1:1000),Intensity_1D(1:1000));

hold off
set(gca,'xlim',[2 8],'xtick',[2:0.5:8],'ylim',[0 0.6]);
set(gca,'LineWidth',3,'box','on','FontSize',30);
xlabel('Energy (keV)','FontSize',30);
grid on

subplot(1,2,2)
hold on
Intensity_1D=sum(data,2)/40000;
plot(E,Intensity_1D,'k-','LineWidth',3);
plot([13.474 13.474],[0 2],'r-','LineWidth',3);
hold off
set(gca,'xlim',[12 14],'xtick',[12:0.5:14]);
set(gca,'LineWidth',3,'box','on','FontSize',30);
xlabel('Energy (keV)','FontSize',30);
grid on






